import _classCallCheck from "@babel/runtime/helpers/esm/classCallCheck";
import _createClass from "@babel/runtime/helpers/esm/createClass";
import _assertThisInitialized from "@babel/runtime/helpers/esm/assertThisInitialized";
import _inherits from "@babel/runtime/helpers/esm/inherits";
import _createSuper from "@babel/runtime/helpers/esm/createSuper";
import _isFunction from "lodash/isFunction";

/**
 * CellControl.js
 * @date 2018/10/11
 */
import React from 'react';
import { Popconfirm } from 'antd';
import intl from 'utils/intl';
import styles from "../../index.less?modules";

var CellControl = /*#__PURE__*/function (_React$Component) {
  _inherits(CellControl, _React$Component);

  var _super = _createSuper(CellControl);

  function CellControl(props) {
    var _this;

    _classCallCheck(this, CellControl);

    _this = _super.call(this, props);
    _this.handleRemoveTrigger = _this.handleRemoveTrigger.bind(_assertThisInitialized(_this));
    return _this;
  }

  _createClass(CellControl, [{
    key: "render",
    value: function render() {
      var _this$props = this.props,
          currentEditField = _this$props.currentEditField,
          isOverAndCanDrop = _this$props.isOverAndCanDrop,
          component = _this$props.component,
          children = _this$props.children;
      var cellControlClassName = [styles['cell-control']];
      var isCurrentEditField = currentEditField === component;

      if (isCurrentEditField) {
        cellControlClassName.push(styles['cell-control-active']);
      }

      if (isOverAndCanDrop) {
        cellControlClassName.push(styles['cell-control-over']);
      }

      return /*#__PURE__*/React.createElement("div", {
        className: cellControlClassName.join(' ')
      }, /*#__PURE__*/React.createElement("div", {
        className: styles['cell-control-component']
      }, children), /*#__PURE__*/React.createElement("i", {
        className: styles['cell-control-remove']
      }, /*#__PURE__*/React.createElement(Popconfirm, {
        onConfirm: this.handleRemoveTrigger,
        title: intl.get('cpfm.ui.message.field.removeTitle').d('是否确认删除')
      }, /*#__PURE__*/React.createElement("i", {
        className: "anticon"
      }))));
    }
  }, {
    key: "handleRemoveTrigger",
    value: function handleRemoveTrigger(e) {
      e.stopPropagation();
      var _this$props2 = this.props,
          onRemoveField = _this$props2.onRemoveField,
          pComponent = _this$props2.pComponent,
          component = _this$props2.component;

      if (_isFunction(onRemoveField)) {
        onRemoveField(pComponent, component);
      }
    }
  }]);

  return CellControl;
}(React.Component);

export { CellControl as default };